<template>
  <div class="toplist">
    <div class="title">
      {{ data.name }}
    </div>
    <div class="top-one">
      <img
        :src="data.pc_image_text"
        alt=""
        @click="goDetail(list[0])"
      >
    </div>
    <div class="top-other">
      <el-carousel
        :interval="5000"
        arrow="always"
        height="29.5rem"
        indicator-position="none"
      >
        <el-carousel-item
          v-for="(item, index) in listTemp"
          :key="index"
        >
          <div 
            v-for="(i,j) in item" 
            :key="j"
            class="goods-item"
            @click="goDetail(i)"
          >
            <!-- <img
              src="../../assets/img/top2@2x.png"
              alt=""
              class="top-img"
            > -->
            <div
              v-if="index * 4 + j + 1 <=2"
              class="top-img"
              :style="{'backgroundImage':'url('+ imgSrc3 +')',backgroundPosition:'center center',backgroundRepeat: 'no-repeat',backgroundPositionX: '100%',backgroundSize: 'contain'}"
            >
              {{ j + 1 }}
            </div>
            <!-- <div class="top-img" v-else :style="{'backgroundImage':'url('+ imgSrc3 +')',backgroundPosition:'center center',backgroundRepeat: 'no-repeat',backgroundPositionX: '100%', backgroundSize: 'contain'}">{{index * 4 + j + 1}}</div> -->
            <img
              :src="i.defaultAlbum"
              alt=""
              class="goods-img"
            >
            <div class="goods-info">
              <p class="name">
                {{ i.pName }}
              </p>
              <p class="price">
                ￥ {{ i.fSalePrice }}
              </p>
            </div>
          </div>
        </el-carousel-item>
      </el-carousel>
    </div>
    <div class="more">
      <img
        src="../../assets/img/logo2.png"
        alt=""
        @click="topList"
      >
    </div>
  </div>
</template>

<script>
export default {
  name: "",
  components: {},
  props: {
    data: {
      type: Object,
      // 对象或数组默认值必须从一个工厂函数获取
      default: function () {
        return {};
      },
    },
    shopid: {
      type: String,
      default: ""
    },
  },
  data() {
    return {
      list:[],
      second: {},
      imgSrc3:require('../../assets/img/tops.png'),
    };
  },
  computed: {
    listTemp: function () {
        var list = this.list;
        var arrTemp = [];
        var index = 0;
        var sectionCount = 4;
        for (var i = 0; i < list.length; i++) {
            index = parseInt(i / sectionCount);
            if (arrTemp.length <= index) {
                arrTemp.push([]);
            }
            arrTemp[index].push(list[i]);
        }
        return arrTemp;
    }
  },
  mounted() {
    this.GetProductMainTopListAPI()
  },
  methods: {
    // top单品
    GetProductMainTopListAPI() {
      let params={
        token:localStorage.getItem("token"),
        queryCondition: {
          order: [
            {
              fieldname: "iOrder",
              direction: "asc",
            },
          ],
          pagesize: 10,
          pageindex: 1,
          where: [
            {
              fieldname: "shop_id",
              valuefrom: this.shopid,
            },
          ],
        }
      }
	  let data = {
	  	shop_id:this.shopid
	  }
      this.$api.home.sales(data).then((res) => {
        if(res.code == 1) {
       
          this.list = res.data // 列表
        }
      })
    },
    topList() {
      this.$router.push({ path: "/top?shop_id="+this.shopid });
    },
    //跳转商品详情
    goDetail(item) {
      console.log('top详情', item)
      this.$router.push({
        path: "/fruit/detail",
        query: {
          id: item.pid,
          iShopId:item.shop_id
        },
      });
    },
  },
};
</script>

<style scoped lang="scss">
.toplist {
  padding: 0 16.19rem;
  margin-top: 2.19rem;
  display: flex;
  flex-direction: column;
  .title {
    width: 11.25rem;
    height: 3.44rem;
    background: rgba(0, 0, 0, 1);
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 1.5rem;
    font-family: Microsoft YaHei;
    font-weight: 400;
    color: rgba(234, 234, 234, 1);
  }
  .top-one {
    width: 100%;
    img {
      width: 100%;
    }
  }
  .top-other {
    margin-top: 1.25rem;
    margin-bottom: 1.25rem;
    .el-carousel__item {
      display: flex;
      align-items: center;
      justify-content: flex-start;
      .goods-item {
        width: 20.94rem;
        height: 100%;
        background: #fff;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: space-around;
        position: relative;
        margin-right: 1.19rem;
        cursor: pointer;
        &:nth-child(4n) {
          margin-right: 0;
        }
        .goods-img {
          width: 15rem;
          height: 15rem;
          object-fit: contain;
        }
        .top-img {
          width: 3.94rem;
          height: 3.94rem;
          position: absolute;
          top: 1.25rem;
          left: 1.56rem;
          text-align: center;
          line-height: 3.94rem;
          color: #fff;
          font-size: 2.5rem;
        }
        .goods-info {
          display: flex;
          flex-direction: column;
          text-align: center;
          padding: 0 1rem;
          .name {
            font-size: 1.13rem;
            font-family: Microsoft YaHei;
            font-weight: 400;
            color: rgba(4, 0, 0, 1);
            overflow: hidden;
            text-overflow: ellipsis;
            white-space: nowrap;
            width: 18rem;
          }
          .price {
            font-size: 1.5rem;
            font-family: Microsoft YaHei;
            font-weight: 400;
            color: rgba(243, 64, 111, 1);
            margin-top: 0.94rem;
          }
        }
      }
    }
  }
  .more {
    height: 2.5rem;
    background: rgba(0, 0, 0, 1);
    display: flex;
    justify-content: flex-end;
    align-items: center;
    padding: 0 1.44rem;
    img {
      width: 7.38rem;
      cursor: pointer;
    }
  }
}
</style>

